// 滚动条只有一个问题$refs的值不知道，导出个函数即可
export default function (refValue) {
	return {
		mounted() {
			if (this.$refs[refValue]) {
				this.$refs[refValue].addEventListener('scroll', this.handleScroll)
				this.$bus.$on('setMainScroll', this.handleSetMainScroll)
			}
		},
		methods: {
			handleScroll() {
				this.$bus.$emit('mainScroll', this.$refs[refValue]) // 滚动则发送mainScroll事件
			},
			handleSetMainScroll(scrollTop) {
				this.$refs[refValue].scrollTop = scrollTop
			},
		},
		beforeDestroy() {
			this.$bus.$emit('mainScroll', undefined)
			this.$bus.$off('setMainScroll', this.handleSetMainScroll)
			if (this.$refs.blogRef) {
				this.$refs.blogRef.removeEventListener('scroll', this.handleScroll)
			}
		},
	}
}
